/**
 * 
 */
package com.app.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.app.dao.ICornDbDao;
import com.app.dao.po.CornDbDna;
import com.app.service.vo.CornDbDnaVo;

/**
 * @author Administrator
 *
 */
public class CornDbDaoImpl extends HibernateDaoSupport implements ICornDbDao {

	/**
	 * 
	 */
	public CornDbDaoImpl() {
		logger.info(this.getClass().getName()+" loader");
	}
	
	private static Logger logger = Logger.getLogger(CornDbDaoImpl.class);

	/* (non-Javadoc)
	 * @see com.app.dao.ICornDbDao#getAll()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<CornDbDnaVo> getAll() {
//		List<CornDbDna> polist = this.getHibernateTemplate().loadAll(CornDbDna.class);
		List<CornDbDna> polist = this.getHibernateTemplate().find("from CornDbDna order by createTime desc");
		List<CornDbDnaVo> volist = new ArrayList<CornDbDnaVo>();
		for(CornDbDna po:polist){
			volist.add((CornDbDnaVo) new CornDbDnaVo().parseVo(po));
		}
		return volist;
	}

	/* (non-Javadoc)
	 * @see com.app.dao.ICornDbDao#getById(java.lang.String)
	 */
	@Override
	public CornDbDnaVo getById(String id) {
		// TODO Auto-generated method stub
		CornDbDna po = this.getHibernateTemplate().get(CornDbDna.class, id);
		CornDbDnaVo vo = (CornDbDnaVo) new CornDbDnaVo().parseVo(po);
		return vo;
	}

	@Override
	public void saveCornDbDnaVo(CornDbDnaVo vo) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(vo.parsePo(new CornDbDna()));
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CornDbDnaVo> getCornDbDnaVoBySql(String hsql) {
		 StringBuilder sb = new StringBuilder(" from CornDbDna where 1=1 "+hsql);
		 List<CornDbDna> polist = this.getHibernateTemplate().find(sb.toString());
		 List<CornDbDnaVo> volist = new ArrayList<CornDbDnaVo>();
		 for(CornDbDna po:polist)
		 {
			 volist.add((CornDbDnaVo) new CornDbDnaVo().parseVo(po));
		 }
		return volist;
	}
	@Override
	public int statCornDbDnaVoBySql(String hsql) {
		 StringBuilder sb = new StringBuilder("select count(*) from CornDbDna where 1=1 "+hsql);
		Integer count = ((Long)this.getHibernateTemplate().find(sb.toString()).listIterator().next()).intValue();
		return count;
	}

}
